package com.startup.yellocar.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.startup.yellocar.dto.SMSProviderDTO;



@Repository
@Transactional
public class SMSProviderDAO {

	@Autowired
	protected SessionFactory sessionFactory;
	
	@Transactional
	public void insert(SMSProviderDTO smsProviderDTO) {
		sessionFactory.getCurrentSession().save(smsProviderDTO);
	}

	@Transactional
	public void update(SMSProviderDTO smsProviderDTO) {
		sessionFactory.getCurrentSession().update(smsProviderDTO);
	}

	@Transactional
	public SMSProviderDTO get(int id) {
		return (SMSProviderDTO) sessionFactory.getCurrentSession().get(
				SMSProviderDTO.class, id);
	}
	
	@Transactional
	@SuppressWarnings("unchecked")
	public List<SMSProviderDTO> getByCredit(long credit) {
		
		List<SMSProviderDTO> listOfReports = sessionFactory
				.getCurrentSession()
				.createQuery(
						"Select r form SMSProviderDTO r where r.credit>=:credit order by r.credit desc")
				.setParameter("credit", credit).list();
		
		return listOfReports;
	}
}
